package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.entity.NursingPlan;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;




@RestController
@RequestMapping("/nursing")
public class NursingPlanController extends BaseController{

    @Autowired
    private NursingPlanService nursingplanservice;


    @GetMapping("/plan")
    public ResponseResult<List<NursingProject>> listAll() {
        List<NursingPlan> nursingPlanList = nursingplanservice.listAll();
        return success(nursingPlanList);
    }

    @PostMapping("/plan")
    public ResponseResult addPlan(@RequestBody NursingPlan planList) {
        nursingplanservice.addPlan(planList);
        return success();
    }


    @GetMapping("/plan/search")
    public ResponseResult<PageResponse> list(
            @RequestParam(value ="name" ,required = false) String name,
            @RequestParam(value ="pageNum",  required = false) Integer pageNum,
            @RequestParam(value ="pageSize", required = false)Integer pageSize,
            @RequestParam(value ="status",required = false) Integer status) {
        PageResponse<NursingPlanVo> Plangpage = nursingplanservice.list(name, pageNum, pageSize, status);

        return success(Plangpage);
    }

    /**
     *2.4 根据id查询
     * */
    @GetMapping("/plan/{id}")
    public ResponseResult<NursingPlanVo> getNursingPlanById(@PathVariable("id") Long id) {
        NursingPlanVo nursingPlanVo = nursingplanservice.getNursingPlanById(id);
        return success(nursingPlanVo);
    }

    /**
     *2.5 修改
     * */
    @PutMapping("/plan/{id}")
    public ResponseResult updateNursingPlanById(@PathVariable("id") Long id, @RequestBody NursingPlanVo nursingPlanVo) {
        nursingPlanVo.setId(id);
        nursingplanservice.updateNursingPlanById(nursingPlanVo);
        return success();
    }

    @DeleteMapping("/plan/{id}")
    public ResponseResult deleteById(@PathVariable("id") Long id) {
        nursingplanservice.deleteById(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    public ResponseResult disableById(@PathVariable("id") Long id,@PathVariable("status") Integer status){
        nursingplanservice.ban(id,status);
        return success();
    }
}
